home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / mutt / me2s_pl7.zoo / mu_edit2 / ed / tokc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-05  |  2.0 KB  |  80 lines

  1. static char rcsid[] = "$Id: tokc.c,v 1.2 1992/12/28 00:41:32 mike Exp $";
  2.  
  3. /* $Log: tokc.c,v $
  4.  * Revision 1.2  1992/12/28  00:41:32  mike
  5.  * - `Eto_keycode' returns 0 in case of an invalid key prefix.
  6.  * - `Eto_keycode' recognizes the `A-' prefix.
  7.  *
  8.  * Revision 1.1  1992/09/14  13:02:14  mike
  9.  * Initial revision
  10.  *
  11.  */
  12.  
  13. /* tokc.c :  Convert a key string to KeyCode
  14.  * For example:
  15.  *   "A" => A
  16.  *   "^A" => C-A
  17.  *   "C-A" => C-A
  18.  * Input:
  19.  *   key_text : pointer to text to convert.
  20.  *   prefixable : 
  21.  * C Durland
  22.  */
  23.  
  24. /* Copyright 1990, 1991 Craig Durland
  25.  *   Distributed under the terms of the GNU General Public License.
  26.  *   Distributed "as is", without warranties of any kind, but comments,
  27.  *     suggestions and bug reports are welcome.
  28.  */
  29.  
  30. #include <char.h>
  31. #include <const.h>
  32. #include "ed.h"
  33.  
  34. extern KeyCode Eprefixes[];
  35.  
  36. KeyCode Eto_keycode(pkeys,key_text,prefixable)
  37.   PKey *pkeys; unsigned char *key_text;
  38. {
  39.   register KeyCode keycode = 0;
  40.   register unsigned char c;
  41.   register int j;
  42.  
  43.   for (; c = *key_text; key_text++)
  44.   {
  45.     if (key_text[1] == '-')    /* maybe its something like "C-A" */
  46.     {
  47.       switch (c)
  48.       {
  49. #ifdef atarist
  50.     default: return 0;        /* Wrong prefix */
  51. #else
  52.     default: goto next;        /* must be just a dash */
  53. #endif
  54.     case 'C' : keycode |= CTRL;   break;
  55.     case 'F' : keycode |= SOFKEY; break;
  56.     case 'M' : keycode |= META;   break;
  57.     case 'S' : keycode |= SHIFT;  break;
  58. #ifdef atarist
  59.     case 'A' : keycode |= PFIX2;  break;
  60. #endif
  61.       }
  62.       key_text++;
  63.       continue;
  64.     }
  65.   next:
  66.     if (iscntrl(c)) keycode |= CTRL | (c ^ 0x40);
  67.     else
  68.       if ((keycode & (CTRL | META | PFIX1 | PFIX2 | PFIX3)) &&
  69.       (keycode & SOFKEY) == 0) keycode |= TOUPPER(c);
  70.       else keycode |= c;
  71.     if (prefixable)
  72.     {
  73.       for (j = PKEYS; j--; )            /* check for prefix keys */
  74.     if (keycode == pkeys[j]) { keycode = Eprefixes[j]; break; }
  75.       prefixable = FALSE;
  76.     }
  77.   }
  78.   return keycode;
  79. }
  80.